{include file="common/header" /}
<div class="admin-mains">
    <div class="admin-main">
        <div class="top-tabs">
            <div class="list">
                <a class="active" href="{:url(CONTROLLER_NAME.'/add')}">添加{$mod.title}</a>
            </div>
            <i class="borderline"></i>
        </div>
        <div class="admin-setting layui-form pad40">
            <form id="form" action="" method="post"> 

                <div class="lines clearfix">
                    <div class="label">模型组名</div>
                    <div class="right">
                        <input type='text' class="layui-input" name="title" value="" autocomplete="off" >
                    </div>
                </div>

                <div class="lines clearfix">
                    <div class="label">示例表</div>
                    <div class="right">
                        {volist name="$exa_res" id="vo"}
                        <input type="checkbox" name="example_ids[{$key}]" lay-skin="primary" value="{$vo.id}" title="{$vo.title}[{$vo.name}]" class="">
                        {/volist}
                    </div>
                </div>
                
                <div class=" mt30">
                    <a class="submit-btn" style="display: inline-block;" href="javascript:;" lay-submit lay-filter="saveBtn" >提交</a>

                    <button type="button" class="layui-btn layui-btn-primary layui-border goback" style="display: inline-block;">返回</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>

    layui.use(['form','iconPickerFa','upload','laydate'], function () {
        var form = layui.form,
            iconPickerFa = layui.iconPickerFa,
            layer = layui.layer,
            upload = layui.upload,
            laydate = layui.laydate,
            $ = layui.$;

        laydate.render({
            elem: '#ID-laydate-demo'
        });

        window.imgdelete = function(dom){
            $(dom).parent().remove();
        }
        $(".goback").click(function(){
            window.location.href = "{:url(CONTROLLER_NAME.'/list')}";
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;

            // var back_new_car_image=$("#image_show .img-item img").map(function(){
            //         return ( $(this).attr("data-url") );
            //     }).get();
            //     data.head_pic = back_new_car_image;
            $.ajax({
                url:"{:url(CONTROLLER_NAME.'/add')}",
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    // layer.close(index);
                    // console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            window.location.href = "{:url(CONTROLLER_NAME.'/list')}";
                        })
                    }
                    layer.close(index);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>
</html>